import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'taskId',
    label: '任务ID',
  },
  {
    component: 'Select',
    componentProps: {
    },
    fieldName: 'operationType',
    label: '操作类型',
  },
  {
    component: 'Input',
    fieldName: 'operationContent',
    label: '操作内容',
  },
  {
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'operationTime',
    label: '操作时间',
  },
  {
    component: 'Input',
    fieldName: 'operationIp',
    label: '操作IP',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_COMMON_STATUS 便于维护
      options: getDictOptions('sys_common_status'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'status',
    label: '状态',
  },
];

// 需要使用i18n注意这里要改成getter形式 否则切换语言不会刷新
// export const columns: () => VxeGridProps['columns'] = () => [
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '日志ID',
    field: 'logId',
  },
  {
    title: '任务ID',
    field: 'taskId',
  },
  {
    title: '操作类型',
    field: 'operationType',
  },
  {
    title: '操作内容',
    field: 'operationContent',
  },
  {
    title: '操作时间',
    field: 'operationTime',
  },
  {
    title: '操作IP',
    field: 'operationIp',
  },
  {
    title: '状态',
    field: 'status',
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.SYS_COMMON_STATUS 便于维护
        return renderDict(row.status, 'sys_common_status');
      },
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    label: '日志ID',
    fieldName: 'logId',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '任务ID',
    fieldName: 'taskId',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '操作类型',
    fieldName: 'operationType',
    component: 'Select',
    componentProps: {
    },
    rules: 'selectRequired',
  },
  {
    label: '操作内容',
    fieldName: 'operationContent',
    component: 'RichTextarea',
    componentProps: {
      // options: {
      //  readyonly: false, // 是否只读
      // }
      // width: '100%', // 宽度
      // showImageUpload: true, // 是否显示图片上传
      // height: 400 // 高度 默认400
    },
    rules: 'required',
  },
  {
    label: '操作时间',
    fieldName: 'operationTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
  {
    label: '操作IP',
    fieldName: 'operationIp',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '状态',
    fieldName: 'status',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.SYS_COMMON_STATUS 便于维护
      options: getDictOptions('sys_common_status'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
];
